<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>

<body>
<?php
//error_reporting(0);
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
$sqlReport = "SELECT `district_id`,`district_name`,`block_id`,`block_name` FROM `tbl_lookup_location` where `district_id` = ".$distId." group by `block_id`";
$queryReport = mysql_query($sqlReport);

?>
<table border="0" width="800" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
	  <font face="Verdana" color="#224568">Block &amp; Scheme wise cost of water</font></span></td>
	</tr>
	
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="800" cellspacing="0" cellpadding="0" height="61" bgcolor="#C5D8EB">
			
			<tr>
			  <td width="83" align="center">
				<font face="Verdana" style="font-size: 8.5pt"><b>Name of the Block</b></font></td>
			  <td width="76" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Type of the Scheme</b></font></td>
			  <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Current Population served (2010)</b></font></td>
		      <td width="56" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Water Supplied (KLD)</b></font></td>
		      <td width="57" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Bill Raised (2008-09) (Rs. Lakhs/annum)</b></font></td>
		      <td width="67" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Revenue Generated (2008-09) (Rs. Lakhs/annum)</b></font></td>
		      <td width="50" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Total O&M cost (Rs. Lakhs/annum)</b></font></td>
		      <td width="53" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Avg. per capita supply (lpcd)</b></font></td>
		      <td width="46" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Avg. O/R Ratio</b></font></td>
		      <td width="73" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Revenue (Rs./KL)</b></font></td>
		      <td width="71" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Avg. O&M Cost (Rs./KL)</b></font></td>
			  <td width="79" align="center"><font style="font-size: 8.5pt" face="Verdana"><b>Avg. O&M Cost/ person/ annum (Rs./person/annum)</b></font></td>
		  </tr>
				
		<?php
		$grandTotalScheme=0;
			while($rowReport = mysql_fetch_array($queryReport)) {
			
			
			$billPnT=getBill_water_Raise($distId,'P&T',$rowReport['block_id'])+getBill_water_Raise($distId,'TSS(P&T)',$rowReport['block_id']);
			$billPiped=getBill_water_Raise($distId,'Piped',$rowReport['block_id']);
			$billSanDigg=getBill_water_Raise($distId,'Sanitary Diggs',$rowReport['block_id']);
			$Totalwater=$billPnT[0]+$billPiped[0]+$billSanDigg[0];
			$Totalbillraised=$billPnT[1]+$billPiped[1]+$billSanDigg[1];
			$Totalrg=$billPnT[2]+$billPiped[2]+$billSanDigg[2];
			$Totalom=$billPnT[3]+$billPiped[3]+$billSanDigg[3];
			$a=getPopulationSchemeBlockWise($distId,'P&T',$rowReport['block_id'])+getPopulationSchemeBlockWise($distId,'TSS(P&T)',$rowReport['block_id']);
			$b=getPopulationSchemeBlockWise($distId,'Piped',$rowReport['block_id']);
			$csan=getPopulationSchemeBlockWise($distId,'Sanitary Diggs',$rowReport['block_id']);
			$total_population=$a+$b+$csan;
			if($a==0)
			{
			 $avg_pnt="0.00";
			}else{
			$avg_pnt=number_format($billPnT[0]*1000/$a,2,'.','');}
			if($b==0)
			{
			 $avg_piped="0.00";
			}else{
			$avg_piped=number_format($billPiped[0]*1000/$b,2,'.','');}
			
			if($csan==0)
			{
			 $avg_san_dig="0.00";
			}else{
			$avg_san_dig=number_format($billSanDigg[0]*1000/$csan,2,'.','');}
			
			$Totalavg_piped=$avg_pnt+$avg_piped+$avg_san_dig;
			if($billPnT[2]==0)
			{
			$or_ratio_pnt=0.00;
			}else{
			$or_ratio_pnt=number_format($billPnT[3]/$billPnT[2],2,'.','');}
			if($billPiped[2]==0)
			{
			$or_ratio_piped=0.00;
			}else{
			$or_ratio_piped=number_format($billPiped[3]/$billPiped[2],2,'.','');}
			
			if($billSanDigg[2]==0)
			{
			$or_ratio_san_dig=0.00;
			}else{
			$or_ratio_san_dig=number_format($billSanDigg[3]/$billSanDigg[2],2,'.','');}
			
			$Totalor_ratio=$or_ratio_piped+$or_ratio_pnt+$or_ratio_san_dig;
			if($billPnT[0]==0)
			{
			$revenue_pnt=0.00;
			}else{
			$revenue_pnt=number_format($billPnT[2]*100000/$billPnT[0]/365,2,'.','');}
			if($billPiped[0]==0)
			{
			$revenue_piped=0.00;
			}else{
			$revenue_piped=number_format($billPiped[2]*100000/$billPiped[0]/365,2,'.','');}
			
			if($billSanDigg[0]==0)
			{
			$revenue_san_digg=0.00;
			}else{
			$revenue_san_digg=number_format($billSanDigg[2]*100000/$billSanDigg[0]/365,2,'.','');}
			
			$Totalrevenue=$revenue_pnt+$revenue_piped+$revenue_san_digg;
			if($billPnT[0]==0)
			{
			$avg_om_pnt=0.00;
			}else{
			$avg_om_pnt=number_format($billPnT[3]*100000/$billPnT[0]/365,2,'.','');}
			if($billPiped[0]==0)
			{
			$avg_om_piped=0.00;
			}else{
			$avg_om_piped=number_format($billPiped[3]*100000/$billPiped[0]/365,2,'.','');}
			
			if($billSanDigg[0]==0)
			{
			$avg_om_san_dig=0.00;
			}else{
			$avg_om_san_dig=number_format($billSanDigg[3]*100000/$billSanDigg[0]/365,2,'.','');}
			
			$Totalavg_om=$avg_om_pnt+$avg_om_piped+$avg_om_san_dig;
			if($a==0)
			{
			$avg1_om_pnt=0.00;
			}else{
			$avg1_om_pnt=number_format($billPnT[3]*100000/$a,2,'.','');}
			if($b==0)
			{
			$avg1_om_piped=0.00;
			}else{
			$avg1_om_piped=number_format($billPiped[3]*100000/$b,2,'.','');}
			
			if($csan==0)
			{
			$avg1_om_san_dig=0.00;
			}else{
			$avg1_om_san_dig=number_format($billSanDigg[3]*100000/$csan,2,'.','');}
			
			$Total_om1=$avg1_om_pnt+$avg1_om_piped+$avg1_om_san_dig;
			$grandTotalScheme+=$total_population;
			 $grandTotalwater+=$Totalwater;
			 $grandTotalbillraised+=$Totalbillraised;
			  $grandTotalrg+=$Totalrg;
			 $grandTotalom+=$Totalom;
			 $grandTotalavg_piped+=$Totalavg_piped;
			 $grandTotalor_ratio+=$Totalor_ratio;
			 $grandTotalrevenue+=$Totalrevenue;
			 $grandTotalavg_om+=$Totalavg_om;
			 $grandTotal_om1+=$Total_om1;
			?>
			<tr  bgcolor="#F9F9F9">
				<td width="83" align="center" rowspan="4" valign="top" bgcolor="#F9F9F9"><font style="font-size: 8.5pt" face="Verdana"><?php echo $rowReport['block_name']; ?></font></td>
				<td width="76" align="center">
				<font style="font-size: 8.5pt" face="Verdana">P &amp; T</font></td>
				<td align="center" width="63"><font style="font-size: 8.5pt" face="Verdana"><?php 
				$pnt_pop=getPopulationSchemeBlockWise($distId,'P&T',$rowReport['block_id'])+getPopulationSchemeBlockWise($distId,'TSS(P&T)',$rowReport['block_id']);
				if($pnt_pop=='')
				{
					echo $pnt_pop=0;
				}
				else
				{
					echo $pnt_pop;
				}
				?></font></td>
				<td align="center" width="56"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPnT[0], 2, '.','');?></font></td>
				<td align="center" width="57"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPnT[1], 2, '.','');?></font></td>
				<td align="center" width="67"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPnT[2], 2, '.','');?></font></td>
				<td align="center" width="50"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPnT[3], 2, '.','');?></font></td>
				<td align="center" width="53"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_pnt,2,'.','');?></font></td>
				<td width="46" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($or_ratio_pnt,2,'.','');?></font></td>
			    <td width="73" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($revenue_pnt,2,'.','');?></font></td>
			    <td width="71" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_om_pnt,2,'.','');?></font></td>
				<td width="79" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg1_om_pnt,2,'.','');?></font></td>
			</tr>
			<tr bgcolor="#F9F9F9">
				<td width="76" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Piped</font></td>
				<td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				$pip_pop=getPopulationSchemeBlockWise($distId,'Piped',$rowReport['block_id']);
				if($pip_pop=='')
				{
					echo $pip_pop=0;
				}
				else
				{
					echo $pip_pop;
				}
				?></font></td>
				<td width="56" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPiped[0], 2, '.','');?></font></td>
				<td width="57" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPiped[1], 2, '.','');?></font></td>
				<td width="67" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPiped[2], 2, '.','');?></font></td>
				<td width="50" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($billPiped[3], 2, '.','');?></font></td>
				<td width="53" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_piped,2,'.',''); ?></font></td>
				<td align="center" width="46"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($or_ratio_piped,2,'.','');?></font></td>
			    <td align="center" width="73"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($revenue_piped,2,'.','');?></font></td>
			    <td align="center" width="71"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_om_piped,2,'.','');?></font></td>
				<td width="79" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg1_om_piped,2,'.','');?></font></td>
			</tr>
			<tr bgcolor="#F9F9F9">
				<td width="76" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Sanitary Diggs</font></td>
				<td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				$san_pop=getPopulationSchemeBlockWise($distId,'Sanitary Diggs',$rowReport['block_id']);
				if($san_pop=='')
				{
					echo $san_pop=0;
				}
				else
				{
					echo $san_pop;
				}
				
				?></font></td>
				<td width="56" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				if($billSanDigg[0]=='')
				{
					echo $billSanDigg[0]="0.00";
				}
				else
				{
					echo number_format($billSanDigg[0],2, '.','');
				}
				?></font></td>
				<td width="57" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				if($billSanDigg[1]=='')
				{
					echo $billSanDigg[1]="0.00";
				}
				else
				{
					echo number_format($billSanDigg[1],2, '.','');
				}
				?></font></td>
				<td width="67" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				if($billSanDigg[2]=='')
				{
					echo $billSanDigg[2]="0.00";
				}
				else
				{
					echo number_format($billSanDigg[2],2, '.','');
				}
				?></font></td>
				<td width="50" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php 
				if($billSanDigg[3]=='')
				{
					echo $billSanDigg[3]="0.00";
				}
				else
				{
					echo number_format($billSanDigg[3],2, '.','');
				}
				?></font></td>
				<td align="center" width="53"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_san_dig,2,'.','');?></font></td>
			    <td align="center" width="46"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($or_ratio_san_dig,2,'.','');?></font></td>
			    <td align="center" width="73"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($revenue_san_digg,2,'.','');?></font></td>
				<td width="71" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg_om_san_dig,2,'.','');?></font></td>
				<td width="79" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($avg1_om_san_dig,2,'.','');?></font></td>
			</tr>
			
			<tr>
				<td width="76" align="center" bgcolor="#E9E9E9">
				<font style="font-size: 8.5pt" face="Verdana"><b>Total</b></font></td>
				<td width="63" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo $total_population;?></b></font></td>
				<td width="56" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($Totalwater,2,'.','');?></b></font></td>
				<td width="57" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($Totalbillraised,2,'.','');?></b></font></td>
				<td width="67" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($Totalrg,2,'.','');?></b></font></td>
				<td width="50" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($Totalom,2,'.','');?></b></font></td>
				<td width="53" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b>
				  <?php //echo $Totalavg_piped;
				if($total_population==0)
				{
					echo "0.00";
				}
				else
				{
					echo number_format($Totalwater*1000/$total_population,2,'.','');
				}
				?>
				</b></font></td>
				<td align="center" width="46" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $Totalor_ratio;
				if($Totalrg==0)
				{
					echo "0.00";
				}
				else
				{
					echo number_format($Totalom/$Totalrg,2,'.','');
				}
				
				
				?></b></font></td>
			    <td align="center" width="73" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $Totalrevenue;
			if($Totalwater==0)
			{
				echo "0.00";
			}else{
				echo number_format($Totalrg*100000/$Totalwater/365,2,'.','');}
				?></b></font></td>
				<td width="71" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $Totalavg_om;
			if($Totalwater==0)
			{
				echo "0.00";
			}else{
			echo number_format($Totalom*100000/$Totalwater/365,2,'.','');}
				?></b></font></td>
				<td width="79" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $Total_om1;
			if($total_population==0)
			{
			echo "0.00";
			}else{
			echo number_format($Totalom*100000/$total_population,2,'.','');}?></b></font></td>
			</tr>
			<?php }?>
			<tr>
				<td colspan="2" align="center" bgcolor="#E9E9E9">
				<font style="font-size: 8.5pt" face="Verdana"><b>Grand Total</b></font></td>
				<td width="63" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo $grandTotalScheme;?></b></font></td>
				<td width="56" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($grandTotalwater,2,'.','');?></b></font></td>
				<td width="57" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($grandTotalbillraised,2,'.','');?></b></font></td>
				<td width="67" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($grandTotalrg,2,'.','');?></b></font></td>
				<td width="50" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php echo number_format($grandTotalom,2,'.','');?></b></font></td>
				<td width="53" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $grandTotalavg_piped;
				if($grandTotalScheme==0)
				{
					echo "0.00";
				}
				else
				{
					echo number_format($grandTotalwater*1000/$grandTotalScheme,2,'.','');
				}
				?></b></font></td>
				<td width="46" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $grandTotalor_ratio;
				if($grandTotalrg==0)
				{
					echo "0.00";
				}
				else
				{
					echo number_format($grandTotalom/$grandTotalrg,2,'.','');
				}
				
				?></b></font></td>
				<td width="73" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $grandTotalrevenue;
			if($grandTotalwater==0)
			{
				echo "0.00";
			}else{
				echo number_format($grandTotalrg*100000/$grandTotalwater/365,2,'.','');}
				
				?></b></font></td>
				<td width="71" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $grandTotalavg_om;
			if($grandTotalwater==0)
			{
				echo "0.00";
			}else{
			echo number_format($grandTotalom*100000/$grandTotalwater/365,2,'.','');}
				?></b></font></td>
				<td width="79" align="center" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><b><?php //echo $grandTotal_om1;
			if($grandTotalScheme==0)
			{
			echo "0.00";
			}else{
			echo number_format($grandTotalom*100000/$grandTotalScheme,2,'.','');}
				?></b></font></td>
			</tr>
		</table>		</td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


</body>

</html>
